{% extends 'layout/manage.html' %}
{% block title %}{% endblock %}

{% block css %}
    <style>
        .project {
            padding: 20px;
        }

        .project a {
            margin-bottom: 20px;
        }

        .project a i {
            padding-right: 5px;
        }

        .panel-body {
            /*弹性布局，相当于float*/
            padding: 0px;
            display: flex;
            flex-direction: row;
            /*从左边开始填内容*/
            justify-content: left;
            /*垂直方向*/
            align-items: flex-start;
            /*内容填满后自动换行*/
            flex-wrap: wrap;
        }

        .panel-body > .item {
            border-radius: 6px;
            width: 228px;
            border: 1px solid #dddddd;
            margin: 20px 10px;
        }

        .panel-body > .item:hover {
            border: 1px solid #f0ad4e;
        }

        .panel-body > .item > .title {
            height: 104px;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            border-top-left-radius: 6px;
            border-top-right-radius: 6px;
            font-size: 15px;
            text-decoration: none;
        }

        .panel-body > .item > .info {
            padding: 10px 10px;
            display: flex;
            justify-content: space-between;
            border-bottom-left-radius: 6px;
            border-bottom-right-radius: 6px;
            color: #8c8c8c;
        }

        .panel-body > .item > .info a {
            text-transform: none;
        }

        .panel-body > .item > .info .fa-star {
            font-size: 18px;
        }
        .color-radio label{
            margin-left: 0px;
            padding-left: 0px;
        }
    .color-radio input[type='radio'] {
        opacity: 0;
        display: none;
    }
    .color-radio input[type='radio'] + .cycle{
        display: inline-block;
        height: 25px;
        width: 25px;
        border-radius: 50%;
        border: 2px solid #dddddd;
    }
    .color-radio input[type='radio']:checked + .cycle{
        border: 2px solid black;
    }
    </style>
{% endblock %}

{% block content %}
    <div class="container-fluid project">
        <!-- 点击a标签，弹出对话框 -->
        <a class="btn btn-primary" data-toggle="modal" data-target="#myModal">
            <i class="fa fa-plus-circle" aria-hidden="true"></i>新建项目
        </a>

        <!-- 面板 -->
        <div class="panel panel-default">
            <div class="panel-heading"><i class="fa fa-star" aria-hidden="true"></i>星标</div>
            <div class="panel-body">
                {% for item in project_dict.star %}
                    <div class="item">
                        <!-- 数据模型对象中的color存的是：(1， '#ffffff'),在这里需要用item.get_color_display显示内容，而不是直接item.color-->
                        <a href="{% url 'web:dashboard' project_id=item.value.id %}" class="title"
                           style="background-color: {{ item.value.get_color_display }}">{{ item.value.project_name }}</a>
                        <div class="info">
                            <div>
                                <a href="{% url 'web:project_unstar' project_type=item.type project_id=item.value.id %}">
                                    <i class="fa fa-star" aria-hidden="true" style="color: orange;"></i>
                                </a>
                                <span>{{ item.value.creator.name }}</span>
                            </div>
                            <div>
                                <i class="fa fa-user-o" aria-hidden="true"></i>
                                <span>{{ item.value.join_count }}</span>
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading"><i class="fa fa-list" aria-hidden="true"></i>我创建</div>
            <div class="panel-body">
                {% for item in project_dict.my %}
                    <div class="item">
                        <a href="{% url 'web:dashboard' project_id=item.id %}" class="title"
                           style="background-color: {{ item.get_color_display }}">{{ item.project_name }}</a>
                        <div class="info">
                            <div>
                                <!-- 方向解析传递参数 -->
                                <a href="{% url 'web:project_star' project_type='my' project_id=item.id %}">
                                    <i class="fa fa-star" aria-hidden="true" style="color: #d5d5d5;"></i>
                                </a>
                                <span>{{ item.creator.name }}</span>
                            </div>
                            <div>
                                <i class="fa fa-user-o" aria-hidden="true"></i>
                                <span>{{ item.join_count }}</span>
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading"><i class="fa fa-handshake-o" aria-hidden="true"></i>我参与</div>
            <div class="panel-body">
                {% for item in project_dict.join %}
                    <div class="item">
                        <a href="{% url 'web:dashboard' project_id=item.id %}" class="title"
                           style="background-color: {{ item.get_color_display }}">{{ item.project_name }}</a>
                        <div class="info">
                           <div>
                                <a href="{% url 'web:project_star' project_type='join' project_id=item.id %}">
                                    <i class="fa fa-star" aria-hidden="true" style="color: #d5d5d5;"></i>
                                </a>
                                <span>{{ item.creator.name }}</span>
                            </div>
                            <div>
                                <i class="fa fa-user-o" aria-hidden="true"></i>
                                <span>{{ item.join_count }}</span>
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        </div>
    </div>

    <!-- 对话框：Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">新建项目</h4>
                </div>
                <div class="modal-body">
                    <form class="addForm" id="addForm">
                        {% csrf_token %}
                        {% for field in form %}
                            <div class="form-group">
                                <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                                {{ field }}
                                <span class="error-msg"></span>
                            </div>
                        {% endfor %}
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                    <button id="btnSubmit" type="button" class="btn btn-primary">确 定</button>
                </div>
            </div>
        </div>
    </div>
{% endblock %}

{% block js %}
    <script>
        $(function () {
            btnSubmit();
        });

        function btnSubmit() {
            $('#btnSubmit').click(function () {
                $.ajax({
                    url: '{% url "web:project_list" %}',
                    type: 'POST',
                    data: $('#addForm').serialize(),
                    dataType: 'JSON',
                    success: function (res) {
                        console.log(res);
                        if (res.status) {
                            location.href = location.href;
                            location
                        } else {

                            $.each(res.error, function (key, value) {
                                $('#id_' + key).next().text(value[0]);
                            });
                        }
                    }
                })
            })
        }
    </script>
{% endblock %}


